package com.lagou.zerocopy;

import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

public class ClientSocket {

    public static void main(String[] args) throws Exception {
        Socket socket = new Socket();
        socket.connect(new InetSocketAddress("127.0.0.1", 6688));
        OutputStream outputStream = socket.getOutputStream();
        String fileName = "Python-2.7.tgz";
        FileInputStream inputStream = new FileInputStream(fileName);
        byte[] bytes = new byte[1024];
        int readLen = 0;
        int total = 0;
        long startTime = System.currentTimeMillis();
        while (readLen >= 0) {
            readLen = inputStream.read(bytes);
            total += readLen;
            outputStream.write(bytes);
            outputStream.flush();
        }
        long endTime = System.currentTimeMillis();
        System.out.println("文件复制用时：" + (endTime - startTime) + ", 文件字节长度为： " + total);

        inputStream.close();
        outputStream.close();
        socket.close();
    }
}
